/**
 * 对第二层数据进行处理
 * @param {array} scoreList 第一层数组
 * @returns {array}
 */
export function parseScoreList (scoreList) {
  return scoreList.reduce((pre, stageScoreList) => [...pre, getScore(stageScoreList)], [])
}

/**
 * 获取分数
 * @param stageScoreList {array} 单个学期的成绩列表
 * @returns {array} 计算后的二维数据
 */
function getScore (stageScoreList) {
  return stageScoreList.reduce((pre, curriculumScoreList) => [...pre, calcScore(curriculumScoreList)], [])
}

/**
 * 分数计算
 * @param curriculumScore {object} 单个课程的成绩
 * @returns {{totalScore: number, onlineScore: number, subject_name: Object.subject_name, endScore: number}}
 */
function calcScore (curriculumScore) {
  const onlineScore = curriculumScore.online_score * curriculumScore.score_config.online_score / 100
  const endScore = curriculumScore.term_score * curriculumScore.score_config.term_score / 100
  const totalScore = onlineScore + endScore
  return {
    subject_name: curriculumScore.subject_name,
    onlineScore,
    endScore,
    totalScore,
  }
}
